<template>
	<view class="page">
		<view class="input justify-content-sp">
			<input type="text" placeholder="请输入手机号或者昵称" v-model="text" />
			<uni-icons type="search" size="20" @click="search"></uni-icons>
		</view>
		<checkbox-group @change="checkboxChange">
			<view class="body " v-for="(item,index) in dataList" :key="item.index" :class="item.is_fz == 2?'gra':''">
				<view class="justify-content-start">
					<view class="check">
						<label>
							<checkbox :value="item.id" :checked="item.checked" class="circle" />
						</label>
					</view>
					<view class="" style="flex: 1;">
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								商家昵称 ：
							</view>
							<view class="body_cont_right justify-content-start">
								{{item.shop_name}}
								<view class="copy_image" @click="copy(item.username)">
									<image src="../../static/index/copy.png" mode="" class="img"></image>
								</view>
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								费率 ：
							</view>
							<view class="body_cont_right">
								{{item.rate}}%
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								商家类型 ：
							</view>
							<view class="body_cont_right">
								{{item.providers_notice}}
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								服务商昵称 ：
							</view>
							<view class="body_cont_right justify-content-start">
								<view class="">
									{{item.username}}
								</view>
								<view class="copy_image" @click="copy(item.username)">
									<image src="../../static/index/copy.png" mode="" class="img"></image>
								</view>
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								服务商 ：
							</view>
							<view class="body_cont_right justify-content-start">
								<view class="">
									{{item.number}}
								</view>
								<view class="copy_image" @click="copy(item.number)">
									<image src="../../static/index/copy.png" mode="" class="img"></image>
								</view>
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								邀请人 ：
							</view>
							<view class="body_cont_right justify-content-start">
								<view class="">
									{{item.invite}}
								</view>
								<view class="copy_image" @click="copy(item.invite)">
									<image src="../../static/index/copy.png" mode="" class="img"></image>
								</view>
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								最后登录 ：
							</view>
							<view class="body_cont_right">
								{{item.last_login_time}}
							</view>
						</view>
						<view class=" justify-content-sp" :class="item.is_fz==2?'body_cont_se2':'body_cont_se'">
							<view class="body_cont_se_left">
								<view class="body_cont_se_left_fir">
									今日交易
								</view>
								<view class="body_cont_se_left_se">
									￥{{item.today_money}}
								</view>
								<view class="body_cont_se_left_thr">
									可用余额
								</view>
								<view class="body_cont_se_left_four">
									￥{{item.now_money}}
								</view>
							</view>
							<view class="body_cont_se_right">
								<view class="body_cont_se_right_fir">
									待结算
								</view>
								<view class="body_cont_se_right_se">
									￥{{item.today_no_settlement}}
								</view>
								<view class="body_cont_se_right_thr">
									总余额
								</view>
								<view class="body_cont_se_right_four">
									￥{{item.money}}
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="text" v-if="item.is_fz == 2">
					<view class="text_1" style="margin-top: 150px;">
						该商家涉嫌违规已被限制
					</view>
					<view class="text_2">
						详情联系客服热线
					</view>
					<view class="text_3">
						{{item.service_tel}}
					</view>
				</view>
				<view class="body_cont_thr justify-content-sp">
					<view class="btn_css" @click="open_popup(item.Qr_code)">
						收款码
					</view>
					<view class="">
						|
					</view>
					<view class="btn_css" @click="goPath(item.shop_id)">
						交易记录
					</view>
				</view>
			</view>
		</checkbox-group>
		<uni-popup ref="status" type="center" border-radius="10px 10px 0 0">
			<view class="status_popup">
				<view class="status_popup_title">
					{{status_ == 0?'解封类型':'限制类型'}}
				</view>
				<view class="status_popup_cont">
					<uni-data-select v-model="limit_index" :localdata="sexList"
						@change="limit_index_change"></uni-data-select>
				</view>
				<view class="btn btn_css" @click="next">
					确定
				</view>
			</view>
		</uni-popup>
		<view style="height: 50px; background-color: #f5f5f5;">
		</view>
		<view class="btn_cs justify-content-sp">
			<view class="">
				<checkbox-group @change="choose_isAll">
					<label>
						<checkbox value="isAll" :checked="isAll" style="transform:scale(0.7)" />全选
					</label>
				</checkbox-group>
			</view>
			<view class="btn_cs_right justify-content-start">
				<view class="btn_css" @click="toPath(1)">
					新增
				</view>
				<view class="btn_css" @click="del">
					删除
				</view>
			</view>
		</view>
		<uni-popup ref="popup" type="bottom" border-radius="10px 10px 0 0">
			<view class="popup_css">
				<view class="popup_css_title">
					收款码
				</view>
				<view class="image">
					<image :src="QR_code" mode="" class="img"></image>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getBusinessList,
		delSviceShop
	} from '../../api/busList/index.js'
	export default {
		data() {
			return {
				QR_code: '',
				limit_index: '',
				type_index: '',
				text: '',
				dataList: [],
				isAll: false,
				sexList: [],
				status_: 0,
				change_type_index: '',
				indexList: []
			}
		},
		onLoad() {},
		onShow() {
			this.page = 1;
			this.dataList = [];
			this.init();
		},
		methods: {
			init() {
				var data = {
					phone: this.text,
				}
				getBusinessList(data).then(res => {
					for (var i = 0; i < res.data.length; i++) {
						res.data[i].checked = false;
					};
					this.dataList.push(...res.data)
				})
			},
			// 复制到剪贴板
			copy(e) {
				console.log(e);
				uni.setClipboardData({
					data: e,
					success: function() {
						console.log(e);
					}
				});
			},
			change_type(e) {
				this.change_type_index = e;
			},
			next() {
				if (this.status_ == 0) {
					console.log("解封类型");
					this.$refs.status.close('center')
				} else if (this.status_ == 1) {
					console.log("限制类型");
					this.$refs.status.close('center')
				}
			},
			open() {
				if (this.status_ == 1) {
					console.log("限制类型");
					this.sexList = [{
							id: 0,
							value: "0",
							text: "关闭收款",
						},
						{
							id: 1,
							value: "1",
							text: "关闭提现",
						}
					]
				} else if (this.status_ == 0) {
					this.sexList = [{
							id: 0,
							value: "0",
							text: "恢复收款",
						},
						{
							id: 1,
							value: "1",
							text: "恢复提现",
						}
					]
				}
				this.$refs.status.open('center')
			},
			choose_isAll(e) {
				console.log(e.detail.value);
				if (e.detail.value[0] == "isAll") {
					for (var i = 0; i < this.dataList.length; i++) {
						this.dataList[i].checked = true;
						this.indexList.push(this.dataList[i].id);
					}
				} else {
					for (var i = 0; i < this.dataList.length; i++) {
						this.dataList[i].checked = false;
					};
					this.indexList = []
				};
			},
			checkboxChange: function(e) {
				var values = e.detail.value;
				this.indexList = e.detail.value;
				for (var i = 0, lenI = this.dataList.length; i < lenI; ++i) {
					const item = this.dataList[i]
					if (values.includes(item.value)) {
						this.$set(item, 'checked', true)
					} else {
						this.$set(item, 'checked', false)
					}
				}
			},
			// 搜索
			search() {
				this.init()
			},
			// 复制
			open_popup(e) {
				this.QR_code = e;
				this.$refs.popup.open('center')
			},
			// 更换
			limit_index_change(e) {
				console.log("e:", e);
				this.limit_index = e;
			},
			// 删除
			del() {
				let newArr = this.indexList.join(',');
				console.log(newArr);
				var data = {
					shop_id: newArr,
					user_role: '商家'
				}
				delSviceShop(data).then(res => {
					uni.showToast({
						"icon": "none",
						"title": res.msg,
						"duration": 1500
					})
					this.page = 1;
					this.dataList = [];
					this.init();
				})
			},
			toPath(e) {
				console.log(e);
				if (e == 1) {
					uni.navigateTo({
						url: '/pages/business/addBusiness'
					})
				} else if (e == 2) {
					uni.navigateTo({
						url: '/pages/daily/index'
					})
				}
			},
			goPath(e) {
				uni.navigateTo({
					url: '/pages/daily/index?id=' + e
				})
			},
			topathUrl(e) {
				uni.navigateTo({
					url: `/pages/merchantListings/addMerchantListings?id=` + e.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100%;

		.input {
			margin: 30rpx;
			padding: 20rpx 40rpx;
			border-radius: 50rpx;
			background-color: white;
		}

		.gra {
			background-color: #666666;
		}

		.gra2 {
			background-color: #666666;
		}

		.text {
			position: absolute;
			color: white;
			margin-top: -353px;
			height: 368px;
			margin-left: -15px;
			width: 690rpx;
			border-radius: 15rpx;
			text-align: center;

			.text_1 {
				margin-top: 100px;
				line-height: 25px;
			}

			.text_2 {
				line-height: 25px;
			}

			.text_3 {
				font-size: 30px;
			}
		}

		.body {
			box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.3);

			.check {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
			}


			.body_cont {
				line-height: 25px;

				.body_cont_left {
					color: black;
				}

				.body_cont_right {}
			}

			.body_cont_se {
				background-color: #f5f5f5;
				padding: 30rpx 80rpx;
				margin: 30rpx 0;
				border-radius: 15rpx;

				.body_cont_se_left {
					text-align: center;

					.body_cont_se_left_fir {
						font-size: 14px;
					}

					.body_cont_se_left_se {
						font-weight: 600;
					}

					.body_cont_se_left_thr {
						margin-top: 10rpx;
						font-size: 14px;
					}

					.body_cont_se_left_four {
						color: #32b26c;
						font-weight: 600;
					}
				}

				.body_cont_se_right {
					text-align: center;

					.body_cont_se_right_fir {
						font-size: 14px;
					}

					.body_cont_se_right_se {
						color: red;
						font-weight: 600;
					}

					.body_cont_se_right_thr {
						margin-top: 10rpx;
						font-size: 14px;
					}

					.body_cont_se_right_four {
						font-weight: 600;
					}
				}
			}

			.body_cont_se2 {
				background-color: #626262;
				padding: 30rpx 80rpx;
				margin: 30rpx 0;
				border-radius: 15rpx;

				.body_cont_se_left {
					text-align: center;

					.body_cont_se_left_fir {
						font-size: 14px;
					}

					.body_cont_se_left_se {
						font-weight: 600;
					}

					.body_cont_se_left_thr {
						margin-top: 10rpx;
						font-size: 14px;
					}

					.body_cont_se_left_four {
						color: #164631;
						font-weight: 600;
					}
				}

				.body_cont_se_right {
					text-align: center;

					.body_cont_se_right_fir {
						font-size: 14px;
					}

					.body_cont_se_right_se {
						color: #5e0e0a;
						font-weight: 600;
					}

					.body_cont_se_right_thr {
						margin-top: 10rpx;
						font-size: 14px;
					}

					.body_cont_se_right_four {
						font-weight: 600;
					}
				}
			}

			.body_cont_thr {
				padding: 0 80rpx;
			}
		}

		.btn_cs {
			position: fixed;
			bottom: 0;
			width: 100%;
			background-color: white;
			padding: 30rpx;

			.btn_cs_right {
				padding: 0 30rpx;

				.btn_css {
					border: 1px solid #b2b2b2;
					border-radius: 30rpx;
					margin: 0 30rpx;
					padding: 0 10px;
				}

				.blue {
					background-color: #4b82ff;
					color: white;
					border: 1px solid #4b82ff;
				}
			}
		}

		.status_popup {
			background-color: white;
			width: 500rpx;
			padding: 30rpx;
			border-radius: 30rpx;

			.status_popup_title {
				font-weight: 550;
				padding: 30rpx;
				text-align: center;
			}

			.status_popup_cont {
				padding: 0 30rpx;
			}

			.btn_css {
				margin: 30rpx 0 0 0;
			}
		}

		.popup_css {
			background-color: white;
			margin: 30rpx;
			padding: 30rpx;
			text-align: center;
			border-radius: 30rpx;

			.popup_css_title {
				font-size: 20px;
			}

			.image {
				width: 200px;
				height: 200px;

				.img {
					width: 100%;
					height: 100%;
				}
			}
		}
	}
</style>